#include "SDLRenderer.h"

Renderer::SDLRenderer::SDLRenderer(int width, int height, int depth) : width(width), height(height), depth(depth)
{
	SDL_Init(SDL_INIT_VIDEO);
    screen = SDL_SetVideoMode(width, height, depth, SDL_SWSURFACE);
}

Renderer::SDLRenderer::~SDLRenderer()
{
	SDL_Quit();
}

void Renderer::SDLRenderer::render()
{
	SDL_Flip(screen);
}

void Renderer::SDLRenderer::drawPixel(int x, int y, int color)
{
	unsigned int *ptr = (unsigned int*)screen->pixels;
	int lineoffset = y * (screen->pitch / 4);
	ptr[lineoffset + x] = color; 
}

void Renderer::SDLRenderer::drawPixel(std::vector<std::vector<int>> film)
{
	for (int i = 0; i < width; i++)
	{
		for (int j = 0; j < height; j++)
		{
			unsigned int *ptr = (unsigned int*)screen->pixels;
			int lineoffset = j * (screen->pitch / 4);
			ptr[lineoffset + i] = film[i][j];
		}
	}
}

void Renderer::SDLRenderer::saveScreenShot()
{
	SDL_SaveBMP(screen, "screen.bmp");
}

